home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / PRIVATE.ZIP / _VALIDCH.C < prev    next >
Text File  |  1992-11-21  |  9KB  |  240 lines

  1. #define        CURSES_LIBRARY  1
  2. #include <curses.h>
  3.  
  4. #ifndef        NDEBUG
  5. char *rcsid__validch = "$Header: c:/curses/private/RCS/_validch.c%v 2.0 1992/11/15 03:24:39 MH Rel $";
  6. #endif
  7.  
  8.  
  9.  
  10. /*man-start*********************************************************************
  11.  
  12. *      Table for key code translation of function keys in keypad mode
  13. *      These values are for strict IBM keyboard compatibles only
  14. **man-end**********************************************************************/
  15.  
  16.  
  17. #if    defined (DOS) || defined (OS2)
  18. static chtype kptab[] =
  19. {
  20.  /* Normal Function Keys        */
  21.  0x3b, KEY_F(1), 0x3c, KEY_F(2), 0x3d, KEY_F(3), 0x3e, KEY_F(4),
  22.  0x3f, KEY_F(5), 0x40, KEY_F(6), 0x41, KEY_F(7), 0x42, KEY_F(8),
  23.  0x43, KEY_F(9), 0x44, KEY_F(10),
  24.  
  25.  /* Normal Keypad               */
  26.  0x47, KEY_HOME, 0x48, KEY_UP,   0x49, KEY_PPAGE,
  27.  0x4b, KEY_LEFT, 0x4c, KEY_B2,   0x4d, KEY_RIGHT,
  28.  0x4f, KEY_END,  0x50, KEY_DOWN, 0x51, KEY_NPAGE,
  29.  0x52, KEY_IC,   0x53, KEY_DC,
  30.  
  31.  /* Shft-Function Keys  */
  32.  0x54, KEY_F(11), 0x55, KEY_F(12), 0x56, KEY_F(13), 0x57, KEY_F(14),
  33.  0x58, KEY_F(15), 0x59, KEY_F(16), 0x5a, KEY_F(17), 0x5b, KEY_F(18),
  34.  0x5c, KEY_F(19), 0x5d, KEY_F(20),
  35.  
  36.  /* Ctl-Function Keys   */
  37.  0x5e, KEY_F(21), 0x5f, KEY_F(22), 0x60, KEY_F(23), 0x61, KEY_F(24),
  38.  0x62, KEY_F(25), 0x63, KEY_F(26), 0x64, KEY_F(27), 0x65, KEY_F(28),
  39.  0x66, KEY_F(29), 0x67, KEY_F(30),
  40.  
  41.  /* Alt-Function Keys   */
  42.  0x68, KEY_F(31), 0x69, KEY_F(32), 0x6a, KEY_F(33), 0x6b, KEY_F(34),
  43.  0x6c, KEY_F(35), 0x6d, KEY_F(36), 0x6e, KEY_F(37), 0x6f, KEY_F(38),
  44.  0x70, KEY_F(39), 0x71, KEY_F(40),
  45.  
  46.  /* Control-Keypad              */
  47.  0x77, CTL_HOME, 0x84, CTL_PGUP,
  48.  0x73, CTL_LEFT, 0x74, CTL_RIGHT,
  49.  0x75, CTL_END, 0x76, CTL_PGDN,
  50.  
  51.  /* Alt-Numbers                 */
  52.  0x78, ALT_1, 0x79, ALT_2, 0x7a, ALT_3, 0x7b, ALT_4,
  53.  0x7c, ALT_5, 0x7d, ALT_6, 0x7e, ALT_7, 0x7f, ALT_8,
  54.  0x80, ALT_9, 0x81, ALT_0,
  55.  
  56.  /* Extended codes              */
  57.  0x85, KEY_F(41), 0x86, KEY_F(42), 0x87, KEY_F(43), 0x88, KEY_F(44),
  58.  0x89, KEY_F(45), 0x8a, KEY_F(46), 0x8b, KEY_F(47), 0x8c, KEY_F(48),
  59.  0x03, 0, /* NULL */
  60.  0xff, PADSLASH,     0x0d, PADENTER,      0x0a, CTL_PADENTER,
  61.  0xa6, ALT_PADENTER, 0x53, SHF_PADSTOP,   0xfc, CTL_ENTER,
  62.  0xfa, PADSTAR,      0xfd, PADMINUS,      0xfb, PADPLUS,
  63.  0x93, CTL_PADSTOP,  0x8f, CTL_PADCENTER, 0x90, CTL_PADPLUS,
  64.  0x8e, CTL_PADMINUS, 0x95, CTL_PADSLASH,  0x96, CTL_PADSTAR,
  65.  0x4e, ALT_PADPLUS,  0x4a, ALT_PADMINUS,  0xa4, ALT_PADSLASH,
  66.  0x37, ALT_PADSTAR,  0x92, CTL_INS,       0xa2, ALT_INS,
  67.  0xa3, ALT_DEL,      0x8d, CTL_UP,        0x91, CTL_DOWN,
  68.  0x94, CTL_TAB,      0xa5, ALT_TAB,       0x82, ALT_MINUS,
  69.  0x83, ALT_EQUAL,    0x99, ALT_PGUP,      0xa1, ALT_PGDN,
  70.  0x9f, ALT_END,      0x98, ALT_UP,        0xa0, ALT_DOWN,
  71.  0x9d, ALT_RIGHT,    0x9b, ALT_LEFT,      0x1c, ALT_ENTER,
  72.  0x97, ALT_HOME,     0x01, ALT_ESC,       0x0e, ALT_BKSP,
  73.  0x29, ALT_BQUOTE,   0x1a, ALT_LBRACKET,  0x1b, ALT_RBRACKET,
  74.  0x27, ALT_SEMICOLON,0x28, ALT_FQUOTE,    0x33, ALT_COMMA,
  75.  0x34, ALT_STOP,     0x35, ALT_FSLASH,    0x2b, ALT_BSLASH,
  76.  
  77.  /* Alt-Alphabet                */
  78.  0x1e, ALT_A, 0x30, ALT_B, 0x2e, ALT_C, 0x20, ALT_D,
  79.  0x12, ALT_E, 0x21, ALT_F, 0x22, ALT_G, 0x23, ALT_H,
  80.  0x17, ALT_I, 0x24, ALT_J, 0x25, ALT_K, 0x26, ALT_L,
  81.  0x32, ALT_M, 0x31, ALT_N, 0x18, ALT_O, 0x19, ALT_P,
  82.  0x10, ALT_Q, 0x13, ALT_R, 0x1f, ALT_S, 0x14, ALT_T,
  83.  0x16, ALT_U, 0x2f, ALT_V, 0x11, ALT_W, 0x2d, ALT_X,
  84.  0x15, ALT_Y, 0x2c, ALT_Z,
  85.  
  86.  0x0f, KEY_BACKTAB,
  87.  
  88.  /* End of kptab[]              */
  89.  0x100, -1
  90. };
  91. #endif
  92.  
  93.  
  94.  
  95.  
  96. #ifdef FLEXOS
  97. chtype kptab[] =
  98. {
  99.  /* Normal Function Keys        */
  100.  0x1001, KEY_F(1), 0x1002, KEY_F(2), 0x1003, KEY_F(3), 0x1004, KEY_F(4),
  101.  0x1005, KEY_F(5), 0x1006, KEY_F(6), 0x1007, KEY_F(7), 0x1008, KEY_F(8),
  102.  0x1009, KEY_F(9), 0x100A, KEY_F(10),
  103.  
  104.  /* Normal Keypad               */
  105.  0x2018, KEY_HOME, 0x2010, KEY_UP, 0x2014, KEY_PPAGE,
  106.  0x2012, KEY_LEFT, 0x2035, KEY_B2, 0x2013, KEY_RIGHT,
  107.  0x2008, KEY_LL, 0x2011, KEY_DOWN, 0x2015, KEY_NPAGE,
  108.  0x2009, KEY_IC, 0x200A, KEY_DC,
  109.  
  110.  /* Shft-Function Keys  */
  111.  0x1401, KEY_F(11), 0x1402, KEY_F(12), 0x1403, KEY_F(13), 0x1404, KEY_F(14),
  112.  0x1405, KEY_F(15), 0x1406, KEY_F(16), 0x1407, KEY_F(17), 0x1408, KEY_F(18),
  113.  0x1409, KEY_F(19), 0x140A, KEY_F(20),
  114.  
  115.  /* Ctl-Function Keys   */
  116.  0x1101, KEY_F(21), 0x1102, KEY_F(22), 0x1103, KEY_F(23), 0x1104, KEY_F(24),
  117.  0x1105, KEY_F(25), 0x1106, KEY_F(26), 0x1107, KEY_F(27), 0x1108, KEY_F(28),
  118.  0x1109, KEY_F(29), 0x110A, KEY_F(30),
  119.  
  120.  /* Alt-Function Keys   */
  121.  0x1201, KEY_F(31), 0x1202, KEY_F(32), 0x1203, KEY_F(33), 0x1204, KEY_F(34),
  122.  0x1205, KEY_F(35), 0x1206, KEY_F(36), 0x1207, KEY_F(37), 0x1208, KEY_F(38),
  123.  0x1209, KEY_F(39), 0x120A, KEY_F(40),
  124.  
  125.  /* Control-Keypad              */
  126.  0x2118, CTL_HOME, 0x2114, CTL_PGUP,
  127.  0x2112, CTL_LEFT, 0x2113, CTL_RIGHT,
  128.  0x2108, CTL_END, 0x2115, CTL_PGDN,
  129.  
  130.  /* Alt-Numbers                 */
  131.  0x2231, ALT_1, 0x2232, ALT_2, 0x2233, ALT_3, 0x2234, ALT_4,
  132.  0x2235, ALT_5, 0x2236, ALT_6, 0x2237, ALT_7, 0x2238, ALT_8,
  133.  0x2239, ALT_9, 0x2230, ALT_0,
  134.  
  135.  /* Alt-Alphabet                */
  136.  0x0200 | (unsigned) 'A', ALT_A, 0x0200 | (unsigned) 'B', ALT_B,
  137.  0x0200 | (unsigned) 'C', ALT_C, 0x0200 | (unsigned) 'D', ALT_D,
  138.  0x0200 | (unsigned) 'E', ALT_E, 0x0200 | (unsigned) 'F', ALT_F,
  139.  0x0200 | (unsigned) 'G', ALT_G, 0x0200 | (unsigned) 'H', ALT_H,
  140.  0x0200 | (unsigned) 'I', ALT_I, 0x0200 | (unsigned) 'J', ALT_J,
  141.  0x0200 | (unsigned) 'K', ALT_K, 0x0200 | (unsigned) 'L', ALT_L,
  142.  0x0200 | (unsigned) 'M', ALT_M, 0x0200 | (unsigned) 'N', ALT_N,
  143.  0x0200 | (unsigned) 'O', ALT_O, 0x0200 | (unsigned) 'P', ALT_P,
  144.  0x0200 | (unsigned) 'Q', ALT_Q, 0x0200 | (unsigned) 'R', ALT_R,
  145.  0x0200 | (unsigned) 'S', ALT_S, 0x0200 | (unsigned) 'T', ALT_T,
  146.  0x0200 | (unsigned) 'U', ALT_U, 0x0200 | (unsigned) 'V', ALT_V,
  147.  0x0200 | (unsigned) 'W', ALT_W, 0x0200 | (unsigned) 'X', ALT_X,
  148.  0x0200 | (unsigned) 'Y', ALT_Y, 0x0200 | (unsigned) 'Z', ALT_Z,
  149.  
  150.  0x0200 | (unsigned) 'a', ALT_A, 0x0200 | (unsigned) 'b', ALT_B,
  151.  0x0200 | (unsigned) 'c', ALT_C, 0x0200 | (unsigned) 'd', ALT_D,
  152.  0x0200 | (unsigned) 'e', ALT_E, 0x0200 | (unsigned) 'f', ALT_F,
  153.  0x0200 | (unsigned) 'g', ALT_G, 0x0200 | (unsigned) 'h', ALT_H,
  154.  0x0200 | (unsigned) 'i', ALT_I, 0x0200 | (unsigned) 'j', ALT_J,
  155.  0x0200 | (unsigned) 'k', ALT_K, 0x0200 | (unsigned) 'l', ALT_L,
  156.  0x0200 | (unsigned) 'm', ALT_M, 0x0200 | (unsigned) 'n', ALT_N,
  157.  0x0200 | (unsigned) 'o', ALT_O, 0x0200 | (unsigned) 'p', ALT_P,
  158.  0x0200 | (unsigned) 'q', ALT_Q, 0x0200 | (unsigned) 'r', ALT_R,
  159.  0x0200 | (unsigned) 's', ALT_S, 0x0200 | (unsigned) 't', ALT_T,
  160.  0x0200 | (unsigned) 'u', ALT_U, 0x0200 | (unsigned) 'v', ALT_V,
  161.  0x0200 | (unsigned) 'w', ALT_W, 0x0200 | (unsigned) 'x', ALT_X,
  162.  0x0200 | (unsigned) 'y', ALT_Y, 0x0200 | (unsigned) 'z', ALT_Z,
  163.  
  164.  0x0f, KEY_BACKTAB,
  165.  
  166.  /* End of kptab[]              */
  167.  0x100, -1
  168. };
  169. #endif
  170.  
  171.  
  172.  
  173.  
  174. /*----------------------------------------------------------------------
  175. $ PDC_validchar()      - validate/translate passed character
  176. $
  177. $ PDCurses Description:
  178. $      This is a private PDCurses function.
  179. $
  180. $      Checks that 'c' is a valid character, and if so returns it,
  181. $      with function key translation applied if 'w' has keypad mode
  182. $      set.  If char is invalid, returns -1.
  183. $
  184. $ PDCurses Return Value:
  185. $      This function returns -1 if the passed character is invalid, or
  186. $      the WINDOW* 'w' is NULL, or 'w's keypad is not active.
  187. $
  188. $      This function returns 0 under Flexos if the passed character
  189. $      is 0x0300.  (-:Forget why.  --Frotz     911130:-)
  190. $
  191. $      Otherwise, this function returns the PDCurses equivalent of the
  192. $      passed character.  See the function key and key macros in
  193. $      <curses.h>
  194. $
  195. $ PDCurses Errors:
  196. $      There are no errors defined for this routine.
  197. $
  198. $ Portability:
  199. $      PDCurses        chtype  PDC_validchar( chtype c );
  200. $
  201. $----------------------------------------------------------------------
  202. */
  203. chtype PDC_validchar(chtype c)
  204. {
  205. extern WINDOW* _getch_win_;
  206. /* extern      WINDOW* w;*/   /* w defined in wgetch() as static - _getch_win_ */
  207.                         /* is the same window - all references to w changed*/
  208.                         /* to _getch_win_ - marked with @@ */
  209.  
  210.        chtype    *scanp;
  211.  
  212.        if (_getch_win_ == (WINDOW *)NULL)
  213.                return (-1);    /* bad window pointer     */
  214.  
  215. #ifdef FLEXOS
  216.        if (c == 0x0300)
  217.                return (0);     /* special case, ^@ = NULL        */
  218. #endif
  219.        if (!(c & ~A_CHARTEXT)) return (c);  /* normal character */
  220.        if (!(_getch_win_->_use_keypad))        return (-1); /* skip if keys if !keypad mode */
  221.  
  222. #if    defined (DOS) || defined (OS2)
  223.        /*
  224.        * Under DOS, extended keys are in the upper byte.  Shift down for a
  225.        * comparison.
  226.        */
  227.        c = (c >> 8) & A_CHARTEXT;
  228. #endif
  229.        scanp = kptab;
  230.        while (*scanp > 0)      /* search for value              */
  231.        {                       /* (stops on table entry 0x100) */
  232.                if (*scanp++ == c)
  233.                {
  234.                        return (*scanp);        /* found, return it */
  235.                }
  236.                scanp++;
  237.        }
  238.        return( -1 );           /* not found, invalid */
  239. }
  240.